package cn.com.yiqi.wsc.service.app_banner.impl;

import cn.com.yiqi.wsc.common.Result;
import cn.com.yiqi.wsc.common.ResultStatusEnum;
import cn.com.yiqi.wsc.dao.app_banner.AppBannerDao;
import cn.com.yiqi.wsc.dao.app_banner.criteria.AppBannerCriteria;
import cn.com.yiqi.wsc.entity.shop.AppBanner;
import cn.com.yiqi.wsc.entity.shop.AppBannerDTO;
import cn.com.yiqi.wsc.enumeration.CommonEnum;
import cn.com.yiqi.wsc.service.app_banner.PortalAppBannerService;
import cn.com.yiqi.wsc.service.user.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 何刚
 * @version V1.0
 * @Title: PortalAppServiceImpl
 * @Package cn.com.yiqi.wsc.service.app_banner.impl
 * @Description: TODO
 * Copyright: Copyright (c) 2016
 * Company: 成都壹柒互动科技有限公司
 * @date 2017/3/20
 */
@Service
public class PortalAppBannerServiceImpl implements PortalAppBannerService {


    @Autowired
    private AppBannerDao appBannerDao;
    @Autowired
    private UserService userService;

    @Override
    public Result insert(AppBanner appBanner) {

        Result result = new Result();
        result.setStatus(ResultStatusEnum.操作成功.getCode());

        appBanner.setInsertUserId(userService.getCurrentUserId());
        appBanner.setStatus(CommonEnum.DISABLE.getValue().byteValue());
        appBannerDao.insert(appBanner);

        return result;
    }

    @Override
    public Result delete(AppBanner appBanner) {

        Result result = new Result();
        result.setStatus(ResultStatusEnum.操作成功.getCode());

        appBannerDao.delete(appBanner);

        return result;
    }

    @Override
    public Result update(AppBanner appBanner) {

        Result result = new Result();
        result.setStatus(ResultStatusEnum.操作成功.getCode());

        appBannerDao.update(appBanner);

        return result;
    }

    @Override
    public Result detail(AppBannerCriteria criteria) {
        Result result = new Result();
        result.setStatus(ResultStatusEnum.操作成功.getCode());

        appBannerDao.detail(criteria);

        return result;
    }

    @Override
    public Result pageList(AppBannerCriteria criteria) {

        Result result = new Result();
        result.setStatus(ResultStatusEnum.操作成功.getCode());

        PageHelper.startPage(criteria.getCurrentPage(), criteria.getPageSize());

        PageInfo<AppBannerDTO> pageInfo = new PageInfo<>(appBannerDao.pageList(criteria));
        result.putData("list", pageInfo.getList());
        result.putData("total", pageInfo.getTotal());

        return result;
    }

    @Override
    public Result enable(AppBanner appBanner) {

        Result result = new Result();
        result.setStatus(ResultStatusEnum.操作成功.getCode());

        AppBanner banner = new AppBanner();
        banner.setId(appBanner.getId());
        banner.setStatus(CommonEnum.ENABLE.getValue().byteValue());

        appBannerDao.update(banner);

        return result;
    }

    @Override
    public Result disable(AppBanner appBanner) {

        Result result = new Result();
        result.setStatus(ResultStatusEnum.操作成功.getCode());

        AppBanner banner = new AppBanner();
        banner.setId(appBanner.getId());
        banner.setStatus(CommonEnum.DISABLE.getValue().byteValue());

        appBannerDao.update(banner);


        return result;
    }

}
